﻿// Copyright (c) Vitaly Kamiansky. All rights reserved. 
// See License.txt in the project root.

using System;

namespace Property.Reloaders
{
    public class SyncReloader<T> : OutReloader<T>
    {
        protected SyncReloader(Func<T> getValue, Action<T> applyValue, Action<bool> applyStatus)
            : base(applyValue, applyStatus)
        {
            if (getValue == null) throw new ArgumentNullException("getValue");

            _GetValue = getValue;
        }

        //=//

        protected readonly Func<T> _GetValue;

        public override void Go()
        {
            _ApplyStatus(true);
            var value = _GetValue();
            _ApplyStatus(false);
            _ApplyValue(value);
        }
    }
}
